﻿using System;
using System.Collections.Generic;
using System.Web;

using System.IO;
namespace WeiboFilter.KeywordsRelated
{
    /// <summary>
    /// 在website启动阶段，将停用词常驻内存
    /// </summary>
    public class StopWord
    {
        private static Dictionary<string, int> _stopwords = new Dictionary<string, int>();

        public static Dictionary<string,int> stopwords
        {
            get { return _stopwords; }
            private set { _stopwords = value; }
        }
        

        private StopWord() { }
        /// <summary>
        /// 返回停用词的个数
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static int importWordListFile(string filename)
        {
            using (StreamReader reader = new StreamReader(filename))
            {
                string line = reader.ReadLine();
                int n = 0;
                while (line != null)
                {
                    //stopword词典保证不重复
                    if (!stopwords.ContainsKey(line))
                    {
                        stopwords.Add(line, 1);
                        n++;
                    }
                    line = reader.ReadLine();
                }
                return n;
            }

        }
    }
}